<template>
    <div>
        <template v-if="showIntervial">
            <template v-if="switchShow">
                <Time :time="time" :interval="interval" :hash="hash"/>
            </template>
            <template v-else>
                <Time :time="time" :interval="interval" :type="type" :hash="hash"/>
            </template>
        </template>
        <template v-else>
            <Time :time="time" :interval="interval" :type="type" :hash="hash"/>
        </template>
    </div>
</template>

<script>
    import {getDateTimeIntervalMinute} from '@/libs/tools';

    export default {
        name: 'DatetimeInterval',
        props: {
            time: {
                type: [String, Date, Number],
                default() {
                    return new Date();
                }
            },
            interval: {
                type: Number,
                default: 1
            },
            type: {
                type: String,
                default() {
                    return 'datetime';
                }
            },
            showIntervial: {
                type: Boolean,
                default: true
            },
            compareMinute: {
                type: Number,
                default: 5
            },
            hash: {
                type: String,
                default: ''
            }
        },
        computed: {
            switchShow() {
                let minute = getDateTimeIntervalMinute(this.time, new Date());
                if (minute && minute < this.compareMinute) {
                    return true;
                }
                return false;
            }
        },
    };
</script>

<style scoped>

</style>
